# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import copy
import os

from packaging import version

from datadog_checks.cockroachdb.metrics import METRIC_MAP
from datadog_checks.dev import get_docker_hostname, get_here
from datadog_checks.dev.utils import assert_service_checks, get_metadata_metrics

HOST = get_docker_hostname()
PORT = '8080'
HERE = get_here()

COCKROACHDB_VERSION = os.getenv('COCKROACHDB_VERSION')

KNOWN_HISTOGRAMS = {
    'admission_wait_durations_kv',
    'admission_wait_durations_kv_stores',
    'admission_wait_durations_sql_leaf_start',
    'admission_wait_durations_sql_sql_response',
    'admission_wait_durations_sql_kv_response',
    'admission_wait_durations_sql_root_start',
    'liveness_heartbeatlatency',
    'sql.conn.latency',
    'sql.txn.latency',
}

KNOWN_COUNTERS = {
    'addsstable_applications',
    'addsstable_copies',
    'addsstable_proposals',
    'compactor_compactingnanos',
    'compactor_compactions_failure',
    'compactor_compactions_success',
    'compactor_suggestionbytes_compacted',
    'compactor_suggestionbytes_skipped',
    'distsender_batches',
    'distsender_batches_partial',
    'distsender_errors_notleaseholder',
    'distsender_rpc_sent',
    'distsender_rpc_sent_local',
    'distsender_rpc_sent_nextreplicaerror',
    'exec_error',
    'exec_success',
    'gossip_bytes_received',
    'gossip_bytes_sent',
    'gossip_connections_refused',
    'gossip_infos_received',
    'gossip_infos_sent',
    'leases_error',
    'leases_success',
    'leases_transfers_error',
    'leases_transfers_success',
    'liveness_epochincrements',
    'liveness_heartbeatfailures',
    'liveness_heartbeatsuccesses',
    'queue_consistency_process_failure',
    'queue_consistency_process_success',
    'queue_consistency_processingnanos',
    'queue_gc_info_abortspanconsidered',
    'queue_gc_info_abortspangcnum',
    'queue_gc_info_abortspanscanned',
    'queue_gc_info_intentsconsidered',
    'queue_gc_info_intenttxns',
    'queue_gc_info_numkeysaffected',
    'queue_gc_info_pushtxn',
    'queue_gc_info_resolvesuccess',
    'queue_gc_info_resolvetotal',
    'queue_gc_info_transactionspangcaborted',
    'queue_gc_info_transactionspangccommitted',
    'queue_gc_info_transactionspangcpending',
    'queue_gc_info_transactionspanscanned',
    'queue_gc_process_failure',
    'queue_gc_process_success',
    'queue_gc_processingnanos',
    'queue_raftlog_process_failure',
    'queue_raftlog_process_success',
    'queue_raftlog_processingnanos',
    'queue_raftsnapshot_process_failure',
    'queue_raftsnapshot_process_success',
    'queue_raftsnapshot_processingnanos',
    'queue_replicagc_process_failure',
    'queue_replicagc_process_success',
    'queue_replicagc_processingnanos',
    'queue_replicagc_removereplica',
    'queue_replicate_addreplica',
    'queue_replicate_process_failure',
    'queue_replicate_process_success',
    'queue_replicate_processingnanos',
    'queue_replicate_rebalancereplica',
    'queue_replicate_removedeadreplica',
    'queue_replicate_removereplica',
    'queue_replicate_transferlease',
    'queue_split_process_failure',
    'queue_split_process_success',
    'queue_split_processingnanos',
    'queue_tsmaintenance_process_failure',
    'queue_tsmaintenance_process_success',
    'queue_tsmaintenance_processingnanos',
    'raft_commandsapplied',
    'raft_process_tickingnanos',
    'raft_process_workingnanos',
    'raft_rcvd_app',
    'raft_rcvd_appresp',
    'raft_rcvd_dropped',
    'raft_rcvd_heartbeat',
    'raft_rcvd_heartbeatresp',
    'raft_rcvd_prevote',
    'raft_rcvd_prevoteresp',
    'raft_rcvd_prop',
    'raft_rcvd_snap',
    'raft_rcvd_timeoutnow',
    'raft_rcvd_transferleader',
    'raft_rcvd_vote',
    'raft_rcvd_voteresp',
    'raft_ticks',
    'raftlog_truncated',
    'range_adds',
    'range_raftleadertransfers',
    'range_removes',
    'range_snapshots_generated',
    'range_snapshots_normal_applied',
    'range_snapshots_preemptive_applied',
    'range_splits',
    'schedules_BACKUP_failed',
    'schedules_BACKUP_started',
    'schedules_BACKUP_succeeded',
    'sql_bytesin',
    'sql_bytesout',
    'sql_ddl_count',
    'sql_delete_count',
    'sql_distsql_flows_total',
    'sql_distsql_queries_total',
    'sql_distsql_select_count',
    'sql_insert_count',
    'sql_misc_count',
    'sql_query_count',
    'sql_select_count',
    'sql_txn_abort_count',
    'sql_txn_begin_count',
    'sql_txn_commit_count',
    'sql_txn_rollback_count',
    'sql_update_count',
    'timeseries_write_bytes',
    'timeseries_write_errors',
    'timeseries_write_samples',
    'tscache_skl_read_rotations',
    'tscache_skl_write_rotations',
    'txn_abandons',
    'txn_aborts',
    'txn_autoretries',
    'txn_commits',
    'txn_commits1PC',
    'txn_restarts_deleterange',
    'txn_restarts_possiblereplay',
    'txn_restarts_serializable',
    'txn_restarts_writetooold',
    'admission_wait_sum_kv',
    'admission_wait_sum_kv_stores',
    'admission_wait_sum_sql_kv_response',
    'admission_wait_sum_sql_sql_response',
    'changefeed_emitted_messages',
    'changefeed_error_retries',
    'changefeed_failures',
    'jobs_changefeed_resume_retry_error',
    'sql_distsql_contended_queries_count',
    'sql_failure_count',
    'sql_full_scan_count',
    'admission_admitted_sql_sql_response',
    'admission_admitted_sql_leaf_start',
    'admission_wait_sum_sql_leaf_start',
    'admission_requested_kv',
    'admission_requested_kv_stores',
    'admission_errored_sql_root_start',
    'admission_errored_kv',
    'admission_requested_sql_leaf_start',
    'admission_errored_sql_leaf_start',
    'admission_wait_sum_sql_root_start',
    'admission_admitted_kv',
    'admission_admitted_sql_kv_response',
    'admission_admitted_sql_root_start',
    'admission_granter_io_tokens_exhausted_duration_kv',
    'admission_requested_sql_sql_response',
    'admission_errored_sql_kv_response',
    'admission_requested_sql_kv_response',
    'admission_errored_kv_stores',
    'admission_requested_sql_root_start',
    'admission_errored_sql_sql_response',
    'admission_admitted_kv_stores',
    'jobs_backup_fail_or_cancel_completed',
    'jobs_backup_fail_or_cancel_retry_error',
    'jobs_backup_fail_or_cancel_failed',
    'jobs_backup_resume_failed',
    'jobs_backup_resume_retry_error',
    'jobs_backup_resume_completed',
    'rebalancing_queriespersecond',
    'range_merges',
    'sql_new_conns',
    'txnwaitqueue_deadlocks_total',
    'txn_restarts_writetoooldmulti',
    'txn_restarts_unknown',
    'txn_restarts_txnpush',
    'txn_restarts_txnaborted',
    'jobs_auto_create_stats_resume_failed',
    'changefeed_emitted_bytes',
    'jobs_row_level_ttl_resume_completed',
    'jobs_row_level_ttl_resume_failed',
    'jobs_row_level_ttl_rows_selected',
    'jobs_row_level_ttl_rows_deleted',
    'schedules_scheduled_row_level_ttl_executor_failed',
    'exportrequest.delay',
    'follower_reads.success_count',
}

COCKROACHDB_23_METRICS = [
    'abortspanbytes',
    'addsstable.delay.count',
    'addsstable.delay.enginebackpressure.count',
    'admission.admitted.elastic_cpu.bulk_normal_pri.count',
    'admission.admitted.elastic_cpu.count',
    'admission.admitted.elastic_cpu.normal_pri.count',
    'admission.admitted.kv.high_pri.count',
    'admission.admitted.kv.locking_normal_pri.count',
    'admission.admitted.kv.normal_pri.count',
    'admission.admitted.kv_stores.bulk_normal_pri.count',
    'admission.admitted.kv_stores.high_pri.count',
    'admission.admitted.kv_stores.locking_normal_pri.count',
    'admission.admitted.kv_stores.normal_pri.count',
    'admission.admitted.kv_stores.ttl_low_pri.count',
    'admission.admitted.sql_kv_response.locking_normal_pri.count',
    'admission.admitted.sql_kv_response.normal_pri.count',
    'admission.admitted.sql_leaf_start.locking_normal_pri.count',
    'admission.admitted.sql_leaf_start.normal_pri.count',
    'admission.admitted.sql_root_start.locking_normal_pri.count',
    'admission.admitted.sql_root_start.normal_pri.count',
    'admission.admitted.sql_sql_response.locking_normal_pri.count',
    'admission.admitted.sql_sql_response.normal_pri.count',
    'admission.elastic_cpu.acquired_nanos.count',
    'admission.elastic_cpu.available_nanos',
    'admission.elastic_cpu.max_available_nanos.count',
    'admission.elastic_cpu.nanos_exhausted_duration',
    'admission.elastic_cpu.pre_work_nanos.count',
    'admission.elastic_cpu.returned_nanos.count',
    'admission.elastic_cpu.utilization',
    'admission.elastic_cpu.utilization_limit',
    'admission.errored.elastic_cpu.bulk_normal_pri.count',
    'admission.errored.elastic_cpu.count',
    'admission.errored.elastic_cpu.normal_pri.count',
    'admission.errored.kv.high_pri.count',
    'admission.errored.kv.locking_normal_pri.count',
    'admission.errored.kv.normal_pri.count',
    'admission.errored.kv_stores.bulk_normal_pri.count',
    'admission.errored.kv_stores.high_pri.count',
    'admission.errored.kv_stores.locking_normal_pri.count',
    'admission.errored.kv_stores.normal_pri.count',
    'admission.errored.kv_stores.ttl_low_pri.count',
    'admission.errored.sql_kv_response.locking_normal_pri.count',
    'admission.errored.sql_kv_response.normal_pri.count',
    'admission.errored.sql_leaf_start.locking_normal_pri.count',
    'admission.errored.sql_leaf_start.normal_pri.count',
    'admission.errored.sql_root_start.locking_normal_pri.count',
    'admission.errored.sql_root_start.normal_pri.count',
    'admission.errored.sql_sql_response.locking_normal_pri.count',
    'admission.errored.sql_sql_response.normal_pri.count',
    'admission.granter.cpu_load_long_period_duration.kv.count',
    'admission.granter.cpu_load_short_period_duration.kv.count',
    'admission.granter.elastic_io_tokens_available.kv',
    'admission.granter.io_tokens_available.kv',
    'admission.granter.io_tokens_bypassed.kv.count',
    'admission.granter.io_tokens_returned.kv.count',
    'admission.granter.io_tokens_taken.kv.count',
    'admission.granter.slot_adjuster_decrements.kv.count',
    'admission.granter.slot_adjuster_increments.kv.count',
    'admission.granter.slots_exhausted_duration.kv.count',
    'admission.l0_compacted_bytes.kv.count',
    'admission.l0_tokens_produced.kv.count',
    'admission.raft.paused_replicas',
    'admission.raft.paused_replicas_dropped_msgs.count',
    'admission.requested.elastic_cpu.bulk_normal_pri.count',
    'admission.requested.elastic_cpu.count',
    'admission.requested.elastic_cpu.normal_pri.count',
    'admission.requested.kv.high_pri.count',
    'admission.requested.kv.locking_normal_pri.count',
    'admission.requested.kv.normal_pri.count',
    'admission.requested.kv_stores.bulk_normal_pri.count',
    'admission.requested.kv_stores.high_pri.count',
    'admission.requested.kv_stores.locking_normal_pri.count',
    'admission.requested.kv_stores.normal_pri.count',
    'admission.requested.kv_stores.ttl_low_pri.count',
    'admission.requested.sql_kv_response.locking_normal_pri.count',
    'admission.requested.sql_kv_response.normal_pri.count',
    'admission.requested.sql_leaf_start.locking_normal_pri.count',
    'admission.requested.sql_leaf_start.normal_pri.count',
    'admission.requested.sql_root_start.count',
    'admission.requested.sql_root_start.locking_normal_pri.count',
    'admission.requested.sql_root_start.normal_pri.count',
    'admission.requested.sql_sql_response.locking_normal_pri.count',
    'admission.requested.sql_sql_response.normal_pri.count',
    'admission.scheduler_latency_listener.p99_nanos',
    'admission.wait_queue_length.elastic_cpu',
    'admission.wait_queue_length.elastic_cpu.bulk_normal_pri',
    'admission.wait_queue_length.elastic_cpu.normal_pri',
    'admission.wait_queue_length.kv.high_pri',
    'admission.wait_queue_length.kv.locking_normal_pri',
    'admission.wait_queue_length.kv.normal_pri',
    'admission.wait_queue_length.kv_stores.bulk_normal_pri',
    'admission.wait_queue_length.kv_stores.high_pri',
    'admission.wait_queue_length.kv_stores.locking_normal_pri',
    'admission.wait_queue_length.kv_stores.normal_pri',
    'admission.wait_queue_length.kv_stores.ttl_low_pri',
    'admission.wait_queue_length.sql_kv_response.locking_normal_pri',
    'admission.wait_queue_length.sql_kv_response.normal_pri',
    'admission.wait_queue_length.sql_leaf_start.locking_normal_pri',
    'admission.wait_queue_length.sql_leaf_start.normal_pri',
    'admission.wait_queue_length.sql_root_start.locking_normal_pri',
    'admission.wait_queue_length.sql_root_start.normal_pri',
    'admission.wait_queue_length.sql_sql_response.locking_normal_pri',
    'admission.wait_queue_length.sql_sql_response.normal_pri',
    'backup.last_failed_time.kms_inaccessible',
    'batch_requests.bytes.count',
    'batch_requests.cross_region.bytes.count',
    'batch_requests.cross_zone.bytes.count',
    'batch_responses.bytes.count',
    'batch_responses.cross_region.bytes.count',
    'batch_responses.cross_zone.bytes.count',
    'changefeed.aggregator_progress',
    'changefeed.batch_reduction_count',
    'changefeed.buffer_entries.allocated_mem',
    'changefeed.buffer_entries.flush.count',
    'changefeed.buffer_entries.in.count',
    'changefeed.buffer_entries.kv.count',
    'changefeed.buffer_entries.out.count',
    'changefeed.buffer_entries.released.count',
    'changefeed.buffer_entries.resolved.count',
    'changefeed.buffer_entries_mem.acquired.count',
    'changefeed.buffer_entries_mem.released.count',
    'changefeed.buffer_pushback.count',
    'changefeed.bytes.messages_pushback.count',
    'changefeed.checkpoint_progress',
    'changefeed.cloudstorage_buffered_bytes',
    'changefeed.filtered_messages.count',
    'changefeed.flush.messages_pushback.count',
    'changefeed.flushed_bytes.count',
    'changefeed.flushes.count',
    'changefeed.forwarded_resolved_messages.count',
    'changefeed.frontier_updates.count',
    'changefeed.internal_retry_message',
    'changefeed.lagging_ranges',
    'changefeed.messages.messages_pushback.count',
    'changefeed.nprocs_in_flight',
    'changefeed.queue_time.count',
    'changefeed.schema_registry.registrations.count',
    'changefeed.schema_registry.retry.count',
    'changefeed.schemafeed.table_history_scans.count',
    'changefeed.schemafeed.table_metadata.count',
    'changefeed.sink_io_inflight',
    'changefeed.size_based_flushes.count',
    'queue.replicate.replacedecommissioningreplica.error.count',
    'rebalancing.queriespersecond',
    'sql.distsql.flows.count',
    'sql.distsql.queries.count',
    'sys.gc',
    'txnwaitqueue.deadlocks.count',
]
assert COCKROACHDB_23_METRICS == sorted(COCKROACHDB_23_METRICS)

EXPECTED_METRICS = []
for raw_metric_name, metric_name in METRIC_MAP.items():
    if raw_metric_name in KNOWN_HISTOGRAMS or raw_metric_name.endswith(('_durations', '_latency', '_max', '_restarts')):
        metric_name += '.bucket'
    elif raw_metric_name in KNOWN_COUNTERS and not metric_name.endswith('.count'):
        metric_name += '.count'

    EXPECTED_METRICS.append(metric_name)

CHANGEFEED_METRICS = {
    'changefeed.aggregator_progress',
    'changefeed.backfill',
    'changefeed.backfill.pending.ranges',
    'changefeed.batch_reduction_count',
    'changefeed.buffer_entries.allocated_mem',
    'changefeed.buffer_entries.flush.count',
    'changefeed.buffer_entries.in.count',
    'changefeed.buffer_entries.kv.count',
    'changefeed.buffer_entries.out.count',
    'changefeed.buffer_entries.released.count',
    'changefeed.buffer_entries.resolved.count',
    'changefeed.buffer_entries_mem.acquired.count',
    'changefeed.buffer_entries_mem.released.count',
    'changefeed.buffer_pushback.count',
    'changefeed.bytes.messages_pushback.count',
    'changefeed.checkpoint_progress',
    'changefeed.cloudstorage_buffered_bytes',
    'changefeed.emitted_bytes.count',
    'changefeed.emitted.messages.count',
    'changefeed.failures.count',
    'changefeed.filtered_messages.count',
    'changefeed.flush.messages_pushback.count',
    'changefeed.flushed_bytes.count',
    'changefeed.flushes.count',
    'changefeed.forwarded_resolved_messages.count',
    'changefeed.frontier_updates.count',
    'changefeed.internal_retry_message',
    'changefeed.lagging_ranges',
    'changefeed.messages.messages_pushback.count',
    'changefeed.nprocs_in_flight',
    'changefeed.queue_time.count',
    'changefeed.running',
    'changefeed.schema_registry.registrations.count',
    'changefeed.schema_registry.retry.count',
    'changefeed.schemafeed.table_history_scans.count',
    'changefeed.schemafeed.table_metadata.count',
    'changefeed.sink_io_inflight',
    'changefeed.size_based_flushes.count',
    'jobs.changefeed.currently_paused',
    'jobs.changefeed.protected_age_sec',
    'jobs.changefeed.resume.retry.error.count',
    'jobs.changefeed.currently_idle',
    'jobs.changefeed.currently_running',
    'jobs.changefeed.expired_pts_records.count',
    'jobs.changefeed.fail_or_cancel_completed.count',
    'jobs.changefeed.fail_or_cancel_failed.count',
    'jobs.changefeed.fail_or_cancel_retry_error.count',
    'jobs.changefeed.protected_record_count',
    'jobs.changefeed.resume_completed.count',
    'jobs.changefeed.resume_failed.count',
}

ADMISSION_METRICS = {
    'admission.admitted.elastic_cpu.bulk_normal_pri.count',
    'admission.admitted.elastic_cpu.count',
    'admission.admitted.elastic_cpu.normal_pri.count',
    'admission.admitted.kv.count',
    'admission.admitted.kv.high_pri.count',
    'admission.admitted.kv.locking_normal_pri.count',
    'admission.admitted.kv.normal_pri.count',
    'admission.admitted.kv_stores.bulk_normal_pri.count',
    'admission.admitted.kv_stores.count',
    'admission.admitted.kv_stores.high_pri.count',
    'admission.admitted.kv_stores.locking_normal_pri.count',
    'admission.admitted.kv_stores.normal_pri.count',
    'admission.admitted.kv_stores.ttl_low_pri.count',
    'admission.admitted.sql.leaf.start.count',
    'admission.admitted.sql.root.start.count',
    'admission.admitted.sql_kv.response.count',
    'admission.admitted.sql_kv_response.locking_normal_pri.count',
    'admission.admitted.sql_kv_response.normal_pri.count',
    'admission.admitted.sql_leaf_start.locking_normal_pri.count',
    'admission.admitted.sql_leaf_start.normal_pri.count',
    'admission.admitted.sql_root_start.locking_normal_pri.count',
    'admission.admitted.sql_root_start.normal_pri.count',
    'admission.admitted.sql_sql.response.count',
    'admission.admitted.sql_sql_response.locking_normal_pri.count',
    'admission.admitted.sql_sql_response.normal_pri.count',
    'admission.elastic_cpu.acquired_nanos.count',
    'admission.elastic_cpu.available_nanos',
    'admission.elastic_cpu.max_available_nanos.count',
    'admission.elastic_cpu.nanos_exhausted_duration',
    'admission.elastic_cpu.pre_work_nanos.count',
    'admission.elastic_cpu.returned_nanos.count',
    'admission.elastic_cpu.utilization',
    'admission.elastic_cpu.utilization_limit',
    'admission.errored.elastic_cpu.bulk_normal_pri.count',
    'admission.errored.elastic_cpu.count',
    'admission.errored.elastic_cpu.normal_pri.count',
    'admission.errored.kv.count',
    'admission.errored.kv.high_pri.count',
    'admission.errored.kv.locking_normal_pri.count',
    'admission.errored.kv.normal_pri.count',
    'admission.errored.kv_stores.bulk_normal_pri.count',
    'admission.errored.kv_stores.count',
    'admission.errored.kv_stores.high_pri.count',
    'admission.errored.kv_stores.locking_normal_pri.count',
    'admission.errored.kv_stores.normal_pri.count',
    'admission.errored.kv_stores.ttl_low_pri.count',
    'admission.errored.sql.leaf.start.count',
    'admission.errored.sql.root.start.count',
    'admission.errored.sql_kv.response.count',
    'admission.errored.sql_kv_response.locking_normal_pri.count',
    'admission.errored.sql_kv_response.normal_pri.count',
    'admission.errored.sql_leaf_start.locking_normal_pri.count',
    'admission.errored.sql_leaf_start.normal_pri.count',
    'admission.errored.sql_root_start.locking_normal_pri.count',
    'admission.errored.sql_root_start.normal_pri.count',
    'admission.errored.sql_sql.response.count',
    'admission.errored.sql_sql_response.locking_normal_pri.count',
    'admission.errored.sql_sql_response.normal_pri.count',
    'admission.granter.cpu_load_long_period_duration.kv.count',
    'admission.granter.cpu_load_short_period_duration.kv.count',
    'admission.granter.elastic_io_tokens_available.kv',
    'admission.granter.io.tokens.exhausted.duration.kv.count',
    'admission.granter.io_tokens_available.kv',
    'admission.granter.io_tokens_bypassed.kv.count',
    'admission.granter.io_tokens_returned.kv.count',
    'admission.granter.io_tokens_taken.kv.count',
    'admission.granter.slot_adjuster_decrements.kv.count',
    'admission.granter.slot_adjuster_increments.kv.count',
    'admission.granter.slots_exhausted_duration.kv.count',
    'admission.granter.total.slots.kv',
    'admission.granter.used.slots.kv',
    'admission.granter.used.slots.sql.leaf.start',
    'admission.granter.used.slots.sql.root.start',
    'admission.io.overload',
    'admission.l0_compacted_bytes.kv.count',
    'admission.l0_tokens_produced.kv.count',
    'admission.raft.paused_replicas',
    'admission.raft.paused_replicas_dropped_msgs.count',
    'admission.requested.elastic_cpu.bulk_normal_pri.count',
    'admission.requested.elastic_cpu.count',
    'admission.requested.elastic_cpu.normal_pri.count',
    'admission.requested.kv.count',
    'admission.requested.kv.high_pri.count',
    'admission.requested.kv.locking_normal_pri.count',
    'admission.requested.kv.normal_pri.count',
    'admission.requested.kv_stores.bulk_normal_pri.count',
    'admission.requested.kv_stores.count',
    'admission.requested.kv_stores.high_pri.count',
    'admission.requested.kv_stores.locking_normal_pri.count',
    'admission.requested.kv_stores.normal_pri.count',
    'admission.requested.kv_stores.ttl_low_pri.count',
    'admission.requested.sql.leaf.start.count',
    'admission.requested.sql_kv.response.count',
    'admission.requested.sql_kv_response.locking_normal_pri.count',
    'admission.requested.sql_kv_response.normal_pri.count',
    'admission.requested.sql_leaf_start.locking_normal_pri.count',
    'admission.requested.sql_leaf_start.normal_pri.count',
    'admission.requested.sql_root_start.count',
    'admission.requested.sql_root_start.locking_normal_pri.count',
    'admission.requested.sql_root_start.normal_pri.count',
    'admission.requested.sql_sql.response.count',
    'admission.requested.sql_sql_response.locking_normal_pri.count',
    'admission.requested.sql_sql_response.normal_pri.count',
    'admission.scheduler_latency_listener.p99_nanos',
    'admission.wait.queue.length.kv',
    'admission.wait.queue.length.kv_stores',
    'admission.wait.queue.length.sql.leaf.start',
    'admission.wait.queue.length.sql_kv.response',
    'admission.wait.queue.length.sql_sql.response',
    'admission.wait.queue.lengths.sql.root.start',
    'admission.wait_queue_length.elastic_cpu',
    'admission.wait_queue_length.elastic_cpu.bulk_normal_pri',
    'admission.wait_queue_length.elastic_cpu.normal_pri',
    'admission.wait_queue_length.kv.high_pri',
    'admission.wait_queue_length.kv.locking_normal_pri',
    'admission.wait_queue_length.kv.normal_pri',
    'admission.wait_queue_length.kv_stores.bulk_normal_pri',
    'admission.wait_queue_length.kv_stores.high_pri',
    'admission.wait_queue_length.kv_stores.locking_normal_pri',
    'admission.wait_queue_length.kv_stores.normal_pri',
    'admission.wait_queue_length.kv_stores.ttl_low_pri',
    'admission.wait_queue_length.sql_kv_response.locking_normal_pri',
    'admission.wait_queue_length.sql_kv_response.normal_pri',
    'admission.wait_queue_length.sql_leaf_start.locking_normal_pri',
    'admission.wait_queue_length.sql_leaf_start.normal_pri',
    'admission.wait_queue_length.sql_root_start.locking_normal_pri',
    'admission.wait_queue_length.sql_root_start.normal_pri',
    'admission.wait_queue_length.sql_sql_response.locking_normal_pri',
    'admission.wait_queue_length.sql_sql_response.normal_pri',
}

DISTSENDER_METRICS = {
    'distsender.batch_requests.cross_region.bytes.count',
    'distsender.batch_requests.cross_zone.bytes.count',
    'distsender.batch_requests.replica_addressed.bytes.count',
    'distsender.batch_responses.cross_region.bytes.count',
    'distsender.batch_responses.cross_zone.bytes.count',
    'distsender.batch_responses.replica_addressed.bytes.count',
    'distsender.batches.async.sent.count',
    'distsender.batches.async.throttled.count',
    'distsender.batches.partial.count',
    'distsender.batches.total.count',
    'distsender.errors.inleasetransferbackoffs.count',
    'distsender.errors.notleaseholder.count',
    'distsender.rangefeed.catchup_ranges',
    'distsender.rangefeed.error_catchup_ranges.count',
    'distsender.rangefeed.restart_ranges.count',
    'distsender.rangefeed.retry.logical_ops_missing.count',
    'distsender.rangefeed.retry.no_leaseholder.count',
    'distsender.rangefeed.retry.node_not_found.count',
    'distsender.rangefeed.retry.raft_snapshot.count',
    'distsender.rangefeed.retry.range_key_mismatch.count',
    'distsender.rangefeed.retry.range_merged.count',
    'distsender.rangefeed.retry.range_not_found.count',
    'distsender.rangefeed.retry.range_split.count',
    'distsender.rangefeed.retry.rangefeed_closed.count',
    'distsender.rangefeed.retry.replica_removed.count',
    'distsender.rangefeed.retry.send.count',
    'distsender.rangefeed.retry.slow_consumer.count',
    'distsender.rangefeed.retry.store_not_found.count',
    'distsender.rangefeed.retry.stuck.count',
    'distsender.rangefeed.total_ranges',
    'distsender.rangelookups.count',
    'distsender.rpc.addsstable.sent.count',
    'distsender.rpc.adminchangereplicas.sent.count',
    'distsender.rpc.adminmerge.sent.count',
    'distsender.rpc.adminrelocaterange.sent.count',
    'distsender.rpc.adminscatter.sent.count',
    'distsender.rpc.adminsplit.sent.count',
    'distsender.rpc.admintransferlease.sent.count',
    'distsender.rpc.adminunsplit.sent.count',
    'distsender.rpc.adminverifyprotectedtimestamp.sent.count',
    'distsender.rpc.barrier.sent.count',
    'distsender.rpc.checkconsistency.sent.count',
    'distsender.rpc.clearrange.sent.count',
    'distsender.rpc.computechecksum.sent.count',
    'distsender.rpc.conditionalput.sent.count',
    'distsender.rpc.delete.sent.count',
    'distsender.rpc.deleterange.sent.count',
    'distsender.rpc.endtxn.sent.count',
    'distsender.rpc.err.ambiguousresulterrtype.count',
    'distsender.rpc.err.batchtimestampbeforegcerrtype.count',
    'distsender.rpc.err.communicationerrtype.count',
    'distsender.rpc.err.conditionfailederrtype.count',
    'distsender.rpc.err.errordetailtype.count',
    'distsender.rpc.err.indeterminatecommiterrtype.count',
    'distsender.rpc.err.integeroverflowerrtype.count',
    'distsender.rpc.err.intentmissingerrtype.count',
    'distsender.rpc.err.internalerrtype.count',
    'distsender.rpc.err.invalidleaseerrtype.count',
    'distsender.rpc.err.leaserejectederrtype.count',
    'distsender.rpc.err.lockconflicterrtype.count',
    'distsender.rpc.err.mergeinprogresserrtype.count',
    'distsender.rpc.err.mintimestampboundunsatisfiableerrtype.count',
    'distsender.rpc.err.mvcchistorymutationerrtype.count',
    'distsender.rpc.err.nodeunavailableerrtype.count',
    'distsender.rpc.err.notleaseholdererrtype.count',
    'distsender.rpc.err.oprequirestxnerrtype.count',
    'distsender.rpc.err.optimisticevalconflictserrtype.count',
    'distsender.rpc.err.raftgroupdeletederrtype.count',
    'distsender.rpc.err.rangefeedretryerrtype.count',
    'distsender.rpc.err.rangekeymismatcherrtype.count',
    'distsender.rpc.err.rangenotfounderrtype.count',
    'distsender.rpc.err.readwithinuncertaintyintervalerrtype.count',
    'distsender.rpc.err.refreshfailederrtype.count',
    'distsender.rpc.err.replicacorruptionerrtype.count',
    'distsender.rpc.err.replicatooolderrtype.count',
    'distsender.rpc.err.storenotfounderrtype.count',
    'distsender.rpc.err.transactionabortederrtype.count',
    'distsender.rpc.err.transactionpusherrtype.count',
    'distsender.rpc.err.transactionretryerrtype.count',
    'distsender.rpc.err.transactionretrywithprotorefresherrtype.count',
    'distsender.rpc.err.transactionstatuserrtype.count',
    'distsender.rpc.err.txnalreadyencounterederrtype.count',
    'distsender.rpc.err.unsupportedrequesterrtype.count',
    'distsender.rpc.err.writeintenterrtype.count',
    'distsender.rpc.err.writetooolderrtype.count',
    'distsender.rpc.export.sent.count',
    'distsender.rpc.gc.sent.count',
    'distsender.rpc.get.sent.count',
    'distsender.rpc.heartbeattxn.sent.count',
    'distsender.rpc.increment.sent.count',
    'distsender.rpc.initput.sent.count',
    'distsender.rpc.isspanempty.sent.count',
    'distsender.rpc.leaseinfo.sent.count',
    'distsender.rpc.merge.sent.count',
    'distsender.rpc.migrate.sent.count',
    'distsender.rpc.probe.sent.count',
    'distsender.rpc.pushtxn.sent.count',
    'distsender.rpc.put.sent.count',
    'distsender.rpc.queryintent.sent.count',
    'distsender.rpc.querylocks.sent.count',
    'distsender.rpc.queryresolvedtimestamp.sent.count',
    'distsender.rpc.querytxn.sent.count',
    'distsender.rpc.rangestats.sent.count',
    'distsender.rpc.recomputestats.sent.count',
    'distsender.rpc.recovertxn.sent.count',
    'distsender.rpc.refresh.sent.count',
    'distsender.rpc.refreshrange.sent.count',
    'distsender.rpc.requestlease.sent.count',
    'distsender.rpc.resolveintent.sent.count',
    'distsender.rpc.resolveintentrange.sent.count',
    'distsender.rpc.reversescan.sent.count',
    'distsender.rpc.revertrange.sent.count',
    'distsender.rpc.scan.sent.count',
    'distsender.rpc.sent.local.count',
    'distsender.rpc.sent.nextreplicaerror.count',
    'distsender.rpc.sent.total.count',
    'distsender.rpc.subsume.sent.count',
    'distsender.rpc.transferlease.sent.count',
    'distsender.rpc.truncatelog.sent.count',
    'distsender.rpc.writebatch.sent.count',
}

JOBS_METRICS = {
    "jobs.adopt_iterations.count",
    "jobs.auto.create.stats.currently_paused",
    "jobs.auto.create.stats.currently_running",
    "jobs.auto.create.stats.resume_failed.count",
    "jobs.auto_config_env_runner.currently_idle",
    "jobs.auto_config_env_runner.currently_paused",
    "jobs.auto_config_env_runner.currently_running",
    "jobs.auto_config_env_runner.expired_pts_records.count",
    "jobs.auto_config_env_runner.fail_or_cancel_completed.count",
    "jobs.auto_config_env_runner.fail_or_cancel_failed.count",
    "jobs.auto_config_env_runner.fail_or_cancel_retry_error.count",
    "jobs.auto_config_env_runner.protected_age_sec",
    "jobs.auto_config_env_runner.protected_record_count",
    "jobs.auto_config_env_runner.resume_completed.count",
    "jobs.auto_config_env_runner.resume_failed.count",
    "jobs.auto_config_env_runner.resume_retry_error.count",
    "jobs.auto_config_runner.currently_idle",
    "jobs.auto_config_runner.currently_paused",
    "jobs.auto_config_runner.currently_running",
    "jobs.auto_config_runner.expired_pts_records.count",
    "jobs.auto_config_runner.fail_or_cancel_completed.count",
    "jobs.auto_config_runner.fail_or_cancel_failed.count",
    "jobs.auto_config_runner.fail_or_cancel_retry_error.count",
    "jobs.auto_config_runner.protected_age_sec",
    "jobs.auto_config_runner.protected_record_count",
    "jobs.auto_config_runner.resume_completed.count",
    "jobs.auto_config_runner.resume_failed.count",
    "jobs.auto_config_runner.resume_retry_error.count",
    "jobs.auto_config_task.currently_idle",
    "jobs.auto_config_task.currently_paused",
    "jobs.auto_config_task.currently_running",
    "jobs.auto_config_task.expired_pts_records.count",
    "jobs.auto_config_task.fail_or_cancel_completed.count",
    "jobs.auto_config_task.fail_or_cancel_failed.count",
    "jobs.auto_config_task.fail_or_cancel_retry_error.count",
    "jobs.auto_config_task.protected_age_sec",
    "jobs.auto_config_task.protected_record_count",
    "jobs.auto_config_task.resume_completed.count",
    "jobs.auto_config_task.resume_failed.count",
    "jobs.auto_config_task.resume_retry_error.count",
    "jobs.auto_create_stats.currently_idle",
    "jobs.auto_create_stats.expired_pts_records.count",
    "jobs.auto_create_stats.fail_or_cancel_completed.count",
    "jobs.auto_create_stats.fail_or_cancel_failed.count",
    "jobs.auto_create_stats.fail_or_cancel_retry_error.count",
    "jobs.auto_create_stats.protected_age_sec",
    "jobs.auto_create_stats.protected_record_count",
    "jobs.auto_create_stats.resume_completed.count",
    "jobs.auto_create_stats.resume_retry_error.count",
    "jobs.auto_schema_telemetry.currently_idle",
    "jobs.auto_schema_telemetry.currently_paused",
    "jobs.auto_schema_telemetry.currently_running",
    "jobs.auto_schema_telemetry.expired_pts_records.count",
    "jobs.auto_schema_telemetry.fail_or_cancel_completed.count",
    "jobs.auto_schema_telemetry.fail_or_cancel_failed.count",
    "jobs.auto_schema_telemetry.fail_or_cancel_retry_error.count",
    "jobs.auto_schema_telemetry.protected_age_sec",
    "jobs.auto_schema_telemetry.protected_record_count",
    "jobs.auto_schema_telemetry.resume_completed.count",
    "jobs.auto_schema_telemetry.resume_failed.count",
    "jobs.auto_schema_telemetry.resume_retry_error.count",
    "jobs.auto_span_config_reconciliation.currently_idle",
    "jobs.auto_span_config_reconciliation.currently_paused",
    "jobs.auto_span_config_reconciliation.currently_running",
    "jobs.auto_span_config_reconciliation.expired_pts_records.count",
    "jobs.auto_span_config_reconciliation.fail_or_cancel_completed.count",
    "jobs.auto_span_config_reconciliation.fail_or_cancel_failed.count",
    "jobs.auto_span_config_reconciliation.fail_or_cancel_retry_error.count",
    "jobs.auto_span_config_reconciliation.protected_age_sec",
    "jobs.auto_span_config_reconciliation.protected_record_count",
    "jobs.auto_span_config_reconciliation.resume_completed.count",
    "jobs.auto_span_config_reconciliation.resume_failed.count",
    "jobs.auto_span_config_reconciliation.resume_retry_error.count",
    "jobs.auto_sql_stats_compaction.currently_idle",
    "jobs.auto_sql_stats_compaction.currently_paused",
    "jobs.auto_sql_stats_compaction.currently_running",
    "jobs.auto_sql_stats_compaction.expired_pts_records.count",
    "jobs.auto_sql_stats_compaction.fail_or_cancel_completed.count",
    "jobs.auto_sql_stats_compaction.fail_or_cancel_failed.count",
    "jobs.auto_sql_stats_compaction.fail_or_cancel_retry_error.count",
    "jobs.auto_sql_stats_compaction.protected_age_sec",
    "jobs.auto_sql_stats_compaction.protected_record_count",
    "jobs.auto_sql_stats_compaction.resume_completed.count",
    "jobs.auto_sql_stats_compaction.resume_failed.count",
    "jobs.auto_sql_stats_compaction.resume_retry_error.count",
    "jobs.auto_update_sql_activity.currently_idle",
    "jobs.auto_update_sql_activity.currently_paused",
    "jobs.auto_update_sql_activity.currently_running",
    "jobs.auto_update_sql_activity.expired_pts_records.count",
    "jobs.auto_update_sql_activity.fail_or_cancel_completed.count",
    "jobs.auto_update_sql_activity.fail_or_cancel_failed.count",
    "jobs.auto_update_sql_activity.fail_or_cancel_retry_error.count",
    "jobs.auto_update_sql_activity.protected_age_sec",
    "jobs.auto_update_sql_activity.protected_record_count",
    "jobs.auto_update_sql_activity.resume_completed.count",
    "jobs.auto_update_sql_activity.resume_failed.count",
    "jobs.auto_update_sql_activity.resume_retry_error.count",
    "jobs.backup.currently_idle",
    "jobs.backup.currently_paused",
    "jobs.backup.currently_running",
    "jobs.backup.expired_pts_records.count",
    "jobs.backup.fail_or_cancel_completed.count",
    "jobs.backup.fail_or_cancel_failed.count",
    "jobs.backup.fail_or_cancel_retry_error.count",
    "jobs.backup.protected_age_sec",
    "jobs.backup.protected_record_count",
    "jobs.backup.resume_completed.count",
    "jobs.backup.resume_failed.count",
    "jobs.backup.resume_retry_error.count",
    "jobs.changefeed.currently_idle",
    "jobs.changefeed.currently_paused",
    "jobs.changefeed.currently_running",
    "jobs.changefeed.expired_pts_records.count",
    "jobs.changefeed.fail_or_cancel_completed.count",
    "jobs.changefeed.fail_or_cancel_failed.count",
    "jobs.changefeed.fail_or_cancel_retry_error.count",
    "jobs.changefeed.protected_age_sec",
    "jobs.changefeed.protected_record_count",
    "jobs.changefeed.resume.retry.error.count",
    "jobs.changefeed.resume_completed.count",
    "jobs.changefeed.resume_failed.count",
    "jobs.claimed_jobs.count",
    "jobs.create.stats.currently_running",
    "jobs.create_stats.currently_idle",
    "jobs.create_stats.currently_paused",
    "jobs.create_stats.expired_pts_records.count",
    "jobs.create_stats.fail_or_cancel_completed.count",
    "jobs.create_stats.fail_or_cancel_failed.count",
    "jobs.create_stats.fail_or_cancel_retry_error.count",
    "jobs.create_stats.protected_age_sec",
    "jobs.create_stats.protected_record_count",
    "jobs.create_stats.resume_completed.count",
    "jobs.create_stats.resume_failed.count",
    "jobs.create_stats.resume_retry_error.count",
    "jobs.import.currently_idle",
    "jobs.import.currently_paused",
    "jobs.import.currently_running",
    "jobs.import.expired_pts_records.count",
    "jobs.import.fail_or_cancel_completed.count",
    "jobs.import.fail_or_cancel_failed.count",
    "jobs.import.fail_or_cancel_retry_error.count",
    "jobs.import.protected_age_sec",
    "jobs.import.protected_record_count",
    "jobs.import.resume_completed.count",
    "jobs.import.resume_failed.count",
    "jobs.import.resume_retry_error.count",
    "jobs.key_visualizer.currently_idle",
    "jobs.key_visualizer.currently_paused",
    "jobs.key_visualizer.currently_running",
    "jobs.key_visualizer.expired_pts_records.count",
    "jobs.key_visualizer.fail_or_cancel_completed.count",
    "jobs.key_visualizer.fail_or_cancel_failed.count",
    "jobs.key_visualizer.fail_or_cancel_retry_error.count",
    "jobs.key_visualizer.protected_age_sec",
    "jobs.key_visualizer.protected_record_count",
    "jobs.key_visualizer.resume_completed.count",
    "jobs.key_visualizer.resume_failed.count",
    "jobs.key_visualizer.resume_retry_error.count",
    "jobs.metrics.task_failed.count",
    "jobs.migration.currently_idle",
    "jobs.migration.currently_paused",
    "jobs.migration.currently_running",
    "jobs.migration.expired_pts_records.count",
    "jobs.migration.fail_or_cancel_completed.count",
    "jobs.migration.fail_or_cancel_failed.count",
    "jobs.migration.fail_or_cancel_retry_error.count",
    "jobs.migration.protected_age_sec",
    "jobs.migration.protected_record_count",
    "jobs.migration.resume_completed.count",
    "jobs.migration.resume_failed.count",
    "jobs.migration.resume_retry_error.count",
    "jobs.mvcc_statistics_update.currently_idle",
    "jobs.mvcc_statistics_update.currently_paused",
    "jobs.mvcc_statistics_update.currently_running",
    "jobs.mvcc_statistics_update.expired_pts_records.count",
    "jobs.mvcc_statistics_update.fail_or_cancel_completed.count",
    "jobs.mvcc_statistics_update.fail_or_cancel_failed.count",
    "jobs.mvcc_statistics_update.fail_or_cancel_retry_error.count",
    "jobs.mvcc_statistics_update.protected_age_sec",
    "jobs.mvcc_statistics_update.protected_record_count",
    "jobs.mvcc_statistics_update.resume_completed.count",
    "jobs.mvcc_statistics_update.resume_failed.count",
    "jobs.mvcc_statistics_update.resume_retry_error.count",
    "jobs.new_schema_change.currently_idle",
    "jobs.new_schema_change.currently_paused",
    "jobs.new_schema_change.currently_running",
    "jobs.new_schema_change.expired_pts_records.count",
    "jobs.new_schema_change.fail_or_cancel_completed.count",
    "jobs.new_schema_change.fail_or_cancel_failed.count",
    "jobs.new_schema_change.fail_or_cancel_retry_error.count",
    "jobs.new_schema_change.protected_age_sec",
    "jobs.new_schema_change.protected_record_count",
    "jobs.new_schema_change.resume_completed.count",
    "jobs.new_schema_change.resume_failed.count",
    "jobs.new_schema_change.resume_retry_error.count",
    "jobs.poll_jobs_stats.currently_idle",
    "jobs.poll_jobs_stats.currently_paused",
    "jobs.poll_jobs_stats.currently_running",
    "jobs.poll_jobs_stats.expired_pts_records.count",
    "jobs.poll_jobs_stats.fail_or_cancel_completed.count",
    "jobs.poll_jobs_stats.fail_or_cancel_failed.count",
    "jobs.poll_jobs_stats.fail_or_cancel_retry_error.count",
    "jobs.poll_jobs_stats.protected_age_sec",
    "jobs.poll_jobs_stats.protected_record_count",
    "jobs.poll_jobs_stats.resume_completed.count",
    "jobs.poll_jobs_stats.resume_failed.count",
    "jobs.poll_jobs_stats.resume_retry_error.count",
    "jobs.replication_stream_ingestion.currently_idle",
    "jobs.replication_stream_ingestion.currently_paused",
    "jobs.replication_stream_ingestion.currently_running",
    "jobs.replication_stream_ingestion.expired_pts_records.count",
    "jobs.replication_stream_ingestion.fail_or_cancel_completed.count",
    "jobs.replication_stream_ingestion.fail_or_cancel_failed.count",
    "jobs.replication_stream_ingestion.fail_or_cancel_retry_error.count",
    "jobs.replication_stream_ingestion.protected_age_sec",
    "jobs.replication_stream_ingestion.protected_record_count",
    "jobs.replication_stream_ingestion.resume_completed.count",
    "jobs.replication_stream_ingestion.resume_failed.count",
    "jobs.replication_stream_ingestion.resume_retry_error.count",
    "jobs.replication_stream_producer.currently_idle",
    "jobs.replication_stream_producer.currently_paused",
    "jobs.replication_stream_producer.currently_running",
    "jobs.replication_stream_producer.expired_pts_records.count",
    "jobs.replication_stream_producer.fail_or_cancel_completed.count",
    "jobs.replication_stream_producer.fail_or_cancel_failed.count",
    "jobs.replication_stream_producer.fail_or_cancel_retry_error.count",
    "jobs.replication_stream_producer.protected_age_sec",
    "jobs.replication_stream_producer.protected_record_count",
    "jobs.replication_stream_producer.resume_completed.count",
    "jobs.replication_stream_producer.resume_failed.count",
    "jobs.replication_stream_producer.resume_retry_error.count",
    "jobs.restore.currently_idle",
    "jobs.restore.currently_paused",
    "jobs.restore.currently_running",
    "jobs.restore.expired_pts_records.count",
    "jobs.restore.fail_or_cancel_completed.count",
    "jobs.restore.fail_or_cancel_failed.count",
    "jobs.restore.fail_or_cancel_retry_error.count",
    "jobs.restore.protected_age_sec",
    "jobs.restore.protected_record_count",
    "jobs.restore.resume_completed.count",
    "jobs.restore.resume_failed.count",
    "jobs.restore.resume_retry_error.count",
    "jobs.resumed_claimed_jobs.count",
    "jobs.row.level.ttl.currently_paused",
    "jobs.row.level.ttl.currently_running",
    "jobs.row.level.ttl.resume_completed.count",
    "jobs.row.level.ttl.resume_failed.count",
    "jobs.row.level.ttl.rows_deleted.count",
    "jobs.row.level.ttl.rows_selected.count",
    "jobs.row_level_ttl.currently_idle",
    "jobs.row_level_ttl.expired_pts_records.count",
    "jobs.row_level_ttl.fail_or_cancel_completed.count",
    "jobs.row_level_ttl.fail_or_cancel_failed.count",
    "jobs.row_level_ttl.fail_or_cancel_retry_error.count",
    "jobs.row_level_ttl.num_active_spans",
    "jobs.row_level_ttl.protected_age_sec",
    "jobs.row_level_ttl.protected_record_count",
    "jobs.row_level_ttl.resume_retry_error.count",
    "jobs.row_level_ttl.total_expired_rows",
    "jobs.row_level_ttl.total_rows",
    "jobs.running_non_idle",
    "jobs.schema_change.currently_idle",
    "jobs.schema_change.currently_paused",
    "jobs.schema_change.currently_running",
    "jobs.schema_change.expired_pts_records.count",
    "jobs.schema_change.fail_or_cancel_completed.count",
    "jobs.schema_change.fail_or_cancel_failed.count",
    "jobs.schema_change.fail_or_cancel_retry_error.count",
    "jobs.schema_change.protected_age_sec",
    "jobs.schema_change.protected_record_count",
    "jobs.schema_change.resume_completed.count",
    "jobs.schema_change.resume_failed.count",
    "jobs.schema_change.resume_retry_error.count",
    "jobs.schema_change_gc.currently_idle",
    "jobs.schema_change_gc.currently_paused",
    "jobs.schema_change_gc.currently_running",
    "jobs.schema_change_gc.expired_pts_records.count",
    "jobs.schema_change_gc.fail_or_cancel_completed.count",
    "jobs.schema_change_gc.fail_or_cancel_failed.count",
    "jobs.schema_change_gc.fail_or_cancel_retry_error.count",
    "jobs.schema_change_gc.protected_age_sec",
    "jobs.schema_change_gc.protected_record_count",
    "jobs.schema_change_gc.resume_completed.count",
    "jobs.schema_change_gc.resume_failed.count",
    "jobs.schema_change_gc.resume_retry_error.count",
    "jobs.typedesc_schema_change.currently_idle",
    "jobs.typedesc_schema_change.currently_paused",
    "jobs.typedesc_schema_change.currently_running",
    "jobs.typedesc_schema_change.expired_pts_records.count",
    "jobs.typedesc_schema_change.fail_or_cancel_completed.count",
    "jobs.typedesc_schema_change.fail_or_cancel_failed.count",
    "jobs.typedesc_schema_change.fail_or_cancel_retry_error.count",
    "jobs.typedesc_schema_change.protected_age_sec",
    "jobs.typedesc_schema_change.protected_record_count",
    "jobs.typedesc_schema_change.resume_completed.count",
    "jobs.typedesc_schema_change.resume_failed.count",
    "jobs.typedesc_schema_change.resume_retry_error.count",
}

KV_METRICS = {
    'kv.allocator.load_based_lease_transfers.cannot_find_better_candidate.count',
    'kv.allocator.load_based_lease_transfers.delta_not_significant.count',
    'kv.allocator.load_based_lease_transfers.existing_not_overfull.count',
    'kv.allocator.load_based_lease_transfers.follow_the_workload.count',
    'kv.allocator.load_based_lease_transfers.missing_stats_for_existing_stores.count',
    'kv.allocator.load_based_lease_transfers.should_transfer.count',
    'kv.allocator.load_based_replica_rebalancing.cannot_find_better_candidate.count',
    'kv.allocator.load_based_replica_rebalancing.delta_not_significant.count',
    'kv.allocator.load_based_replica_rebalancing.existing_not_overfull.count',
    'kv.allocator.load_based_replica_rebalancing.missing_stats_for_existing_store.count',
    'kv.allocator.load_based_replica_rebalancing.should_transfer.count',
    'kv.closed_timestamp.max_behind_nanos',
    'kv.concurrency.avg_lock_hold_duration_nanos',
    'kv.concurrency.avg_lock_wait_duration_nanos',
    'kv.concurrency.lock_wait_queue_waiters',
    'kv.concurrency.locks',
    'kv.concurrency.locks_with_wait_queues',
    'kv.concurrency.max_lock_hold_duration_nanos',
    'kv.concurrency.max_lock_wait_duration_nanos',
    'kv.concurrency.max_lock_wait_queue_waiters_for_lock',
    'kv.loadsplitter.nosplitkey.count',
    'kv.loadsplitter.popularkey.count',
    'kv.prober.planning_attempts.count',
    'kv.prober.planning_failures.count',
    'kv.prober.read.attempts.count',
    'kv.prober.read.failures.count',
    'kv.prober.write.attempts.count',
    'kv.prober.write.failures.count',
    'kv.prober.write.quarantine.oldest_duration',
    'kv.protectedts.reconciliation.errors.count',
    'kv.protectedts.reconciliation.num_runs.count',
    'kv.protectedts.reconciliation.records_processed.count',
    'kv.protectedts.reconciliation.records_removed.count',
    'kv.rangefeed.budget_allocation_blocked.count',
    'kv.rangefeed.budget_allocation_failed.count',
    'kv.rangefeed.catchup_scan_nanos.count',
    'kv.rangefeed.mem_shared',
    'kv.rangefeed.mem_system',
    'kv.rangefeed.processors_goroutine',
    'kv.rangefeed.processors_scheduler',
    'kv.rangefeed.registrations',
    'kv.rangefeed.scheduler.normal.queue_size',
    'kv.rangefeed.scheduler.system.queue_size',
    'kv.replica_circuit_breaker.num_tripped_events.count',
    'kv.replica_circuit_breaker.num_tripped_replicas',
    'kv.replica_read_batch_evaluate.dropped_latches_before_eval.count',
    'kv.replica_read_batch_evaluate.without_interleaving_iter.count',
    'kv.tenant_rate_limit.current_blocked',
    'kv.tenant_rate_limit.num_tenants',
    'kv.tenant_rate_limit.read_batches_admitted.count',
    'kv.tenant_rate_limit.read_bytes_admitted.count',
    'kv.tenant_rate_limit.read_requests_admitted.count',
    'kv.tenant_rate_limit.write_batches_admitted.count',
    'kv.tenant_rate_limit.write_bytes_admitted.count',
    'kv.tenant_rate_limit.write_requests_admitted.count',
    'kvadmission.flow_controller.elastic_blocked_stream_count',
    'kvadmission.flow_controller.elastic_requests_admitted.count',
    'kvadmission.flow_controller.elastic_requests_bypassed.count',
    'kvadmission.flow_controller.elastic_requests_errored.count',
    'kvadmission.flow_controller.elastic_requests_waiting',
    'kvadmission.flow_controller.elastic_stream_count',
    'kvadmission.flow_controller.elastic_tokens_available',
    'kvadmission.flow_controller.elastic_tokens_deducted.count',
    'kvadmission.flow_controller.elastic_tokens_returned.count',
    'kvadmission.flow_controller.elastic_tokens_unaccounted.count',
    'kvadmission.flow_controller.regular_blocked_stream_count',
    'kvadmission.flow_controller.regular_requests_admitted.count',
    'kvadmission.flow_controller.regular_requests_bypassed.count',
    'kvadmission.flow_controller.regular_requests_errored.count',
    'kvadmission.flow_controller.regular_requests_waiting',
    'kvadmission.flow_controller.regular_stream_count',
    'kvadmission.flow_controller.regular_tokens_available',
    'kvadmission.flow_controller.regular_tokens_deducted.count',
    'kvadmission.flow_controller.regular_tokens_returned.count',
    'kvadmission.flow_controller.regular_tokens_unaccounted.count',
    'kvadmission.flow_handle.elastic_requests_admitted.count',
    'kvadmission.flow_handle.elastic_requests_errored.count',
    'kvadmission.flow_handle.elastic_requests_waiting',
    'kvadmission.flow_handle.regular_requests_admitted.count',
    'kvadmission.flow_handle.regular_requests_errored.count',
    'kvadmission.flow_handle.regular_requests_waiting',
    'kvadmission.flow_handle.streams_connected.count',
    'kvadmission.flow_handle.streams_disconnected.count',
    'kvadmission.flow_token_dispatch.coalesced_elastic.count',
    'kvadmission.flow_token_dispatch.coalesced_regular.count',
    'kvadmission.flow_token_dispatch.local_elastic.count',
    'kvadmission.flow_token_dispatch.local_regular.count',
    'kvadmission.flow_token_dispatch.pending_elastic',
    'kvadmission.flow_token_dispatch.pending_nodes',
    'kvadmission.flow_token_dispatch.pending_regular',
    'kvadmission.flow_token_dispatch.remote_elastic.count',
    'kvadmission.flow_token_dispatch.remote_regular.count',
}

PHYSICAL_METRICS = {
    'physical_replication.cutover_progress',
    'physical_replication.distsql_replan_count.count',
    'physical_replication.earliest_data_checkpoint_span',
    'physical_replication.events_ingested.count',
    'physical_replication.flushes.count',
    'physical_replication.job_progress_updates.count',
    'physical_replication.latest_data_checkpoint_span',
    'physical_replication.logical_bytes.count',
    'physical_replication.replicated_time_seconds',
    'physical_replication.resolved_events_ingested.count',
    'physical_replication.running',
    'physical_replication.sst_bytes.count',
}

QUEUE_METRICS = {
    'queue.consistency.pending',
    'queue.consistency.process.failure.count',
    'queue.consistency.process.success.count',
    'queue.consistency.processingnanos.count',
    'queue.gc.info.abortspanconsidered.count',
    'queue.gc.info.abortspangcnum.count',
    'queue.gc.info.abortspanscanned.count',
    'queue.gc.info.clearrangefailed.count',
    'queue.gc.info.clearrangesuccess.count',
    'queue.gc.info.enqueuehighpriority.count',
    'queue.gc.info.intentsconsidered.count',
    'queue.gc.info.intenttxns.count',
    'queue.gc.info.numkeysaffected.count',
    'queue.gc.info.numrangekeysaffected.count',
    'queue.gc.info.pushtxn.count',
    'queue.gc.info.resolvefailed.count',
    'queue.gc.info.resolvesuccess.count',
    'queue.gc.info.resolvetotal.count',
    'queue.gc.info.transactionresolvefailed.count',
    'queue.gc.info.transactionspangcaborted.count',
    'queue.gc.info.transactionspangccommitted.count',
    'queue.gc.info.transactionspangcpending.count',
    'queue.gc.info.transactionspangcstaging.count',
    'queue.gc.info.transactionspanscanned.count',
    'queue.gc.pending',
    'queue.gc.process.failure.count',
    'queue.gc.process.success.count',
    'queue.gc.processingnanos.count',
    'queue.merge.pending',
    'queue.merge.process.failure.count',
    'queue.merge.process.success.count',
    'queue.merge.processingnanos.count',
    'queue.merge.purgatory',
    'queue.raftlog.pending',
    'queue.raftlog.process.failure.count',
    'queue.raftlog.process.success.count',
    'queue.raftlog.processingnanos.count',
    'queue.raftsnapshot.pending',
    'queue.raftsnapshot.process.failure.count',
    'queue.raftsnapshot.process.success.count',
    'queue.raftsnapshot.processingnanos.count',
    'queue.replicagc.pending',
    'queue.replicagc.process.failure.count',
    'queue.replicagc.process.success.count',
    'queue.replicagc.processingnanos.count',
    'queue.replicagc.removereplica.count',
    'queue.replicate.addnonvoterreplica.count',
    'queue.replicate.addreplica.count',
    'queue.replicate.addreplica.error.count',
    'queue.replicate.addreplica.success.count',
    'queue.replicate.addvoterreplica.count',
    'queue.replicate.nonvoterpromotions.count',
    'queue.replicate.pending',
    'queue.replicate.process.failure.count',
    'queue.replicate.process.success.count',
    'queue.replicate.processingnanos.count',
    'queue.replicate.purgatory',
    'queue.replicate.rebalancenonvoterreplica.count',
    'queue.replicate.rebalancereplica.count',
    'queue.replicate.rebalancevoterreplica.count',
    'queue.replicate.removedeadnonvoterreplica.count',
    'queue.replicate.removedeadreplica.count',
    'queue.replicate.removedeadreplica.error.count',
    'queue.replicate.removedeadreplica.success.count',
    'queue.replicate.removedeadvoterreplica.count',
    'queue.replicate.removedecommissioningnonvoterreplica.count',
    'queue.replicate.removedecommissioningreplica.count',
    'queue.replicate.removedecommissioningreplica.error.count',
    'queue.replicate.removedecommissioningreplica.success.count',
    'queue.replicate.removedecommissioningvoterreplica.count',
    'queue.replicate.removelearnerreplica.count',
    'queue.replicate.removenonvoterreplica.count',
    'queue.replicate.removereplica.count',
    'queue.replicate.removereplica.error.count',
    'queue.replicate.removereplica.success.count',
    'queue.replicate.removevoterreplica.count',
    'queue.replicate.replacedeadreplica.error.count',
    'queue.replicate.replacedeadreplica.success.count',
    'queue.replicate.replacedecommissioningreplica.error.count',
    'queue.replicate.replacedecommissioningreplica.success.count',
    'queue.replicate.transferlease.count',
    'queue.replicate.voterdemotions.count',
    'queue.split.load_based.count',
    'queue.split.pending',
    'queue.split.process.failure.count',
    'queue.split.process.success.count',
    'queue.split.processingnanos.count',
    'queue.split.purgatory',
    'queue.split.size_based.count',
    'queue.split.span_config_based.count',
    'queue.tsmaintenance.pending',
    'queue.tsmaintenance.process.failure.count',
    'queue.tsmaintenance.process.success.count',
    'queue.tsmaintenance.processingnanos.count',
}

RAFT_METRICS = {
    'raft.commands.proposed.count',
    'raft.commands.reproposed.new_lai.count',
    'raft.commands.reproposed.unchanged.count',
    'raft.commandsapplied.count',
    'raft.dropped.count',
    'raft.dropped_leader.count',
    'raft.entrycache.accesses.count',
    'raft.entrycache.bytes',
    'raft.entrycache.hits.count',
    'raft.entrycache.read_bytes.count',
    'raft.entrycache.size',
    'raft.heartbeats.pending',
    'raft.process.tickingnanos.count',
    'raft.process.workingnanos.count',
    'raft.rcvd.app.count',
    'raft.rcvd.appresp.count',
    'raft.rcvd.bytes.count',
    'raft.rcvd.cross_region.bytes.count',
    'raft.rcvd.cross_zone.bytes.count',
    'raft.rcvd.dropped.count',
    'raft.rcvd.dropped_bytes.count',
    'raft.rcvd.heartbeat.count',
    'raft.rcvd.heartbeatresp.count',
    'raft.rcvd.prevote.count',
    'raft.rcvd.prevoteresp.count',
    'raft.rcvd.prop.count',
    'raft.rcvd.queued_bytes',
    'raft.rcvd.snap.count',
    'raft.rcvd.stepped_bytes.count',
    'raft.rcvd.timeoutnow.count',
    'raft.rcvd.transferleader.count',
    'raft.rcvd.vote.count',
    'raft.rcvd.voteresp.count',
    'raft.sent.bytes.count',
    'raft.sent.cross_region.bytes.count',
    'raft.sent.cross_zone.bytes.count',
    'raft.storage.read_bytes.count',
    'raft.ticks.count',
    'raft.timeoutcampaign.count',
    'raft.transport.flow_token_dispatches_dropped.count',
    'raft.transport.rcvd.count',
    'raft.transport.reverse_rcvd.count',
    'raft.transport.reverse_sent.count',
    'raft.transport.send_queue_bytes',
    'raft.transport.send_queue_size',
    'raft.transport.sends_dropped.count',
    'raft.transport.sent.count',
    'range.adds.count',
    'range.merges.count',
    'range.raftleaderremovals.count',
    'range.raftleadertransfers.count',
    'range.recoveries.count',
    'range.removes.count',
    'range.snapshots.applied_initial.count',
    'range.snapshots.applied_non_voter.count',
    'range.snapshots.applied_voter.count',
    'range.snapshots.cross_region.rcvd_bytes.count',
    'range.snapshots.cross_region.sent_bytes.count',
    'range.snapshots.cross_zone.rcvd_bytes.count',
    'range.snapshots.cross_zone.sent_bytes.count',
    'range.snapshots.delegate.failures.count',
    'range.snapshots.delegate.in_progress',
    'range.snapshots.delegate.sent_bytes.count',
    'range.snapshots.delegate.successes.count',
    'range.snapshots.generated.count',
    'range.snapshots.rcvd_bytes.count',
    'range.snapshots.rebalancing.rcvd_bytes.count',
    'range.snapshots.rebalancing.sent_bytes.count',
    'range.snapshots.recovery.rcvd_bytes.count',
    'range.snapshots.recovery.sent_bytes.count',
    'range.snapshots.recv_failed.count',
    'range.snapshots.recv_in_progress',
    'range.snapshots.recv_queue',
    'range.snapshots.recv_queue_bytes',
    'range.snapshots.recv_total_in_progress',
    'range.snapshots.recv_unusable.count',
    'range.snapshots.send_in_progress',
    'range.snapshots.send_queue',
    'range.snapshots.send_queue_bytes',
    'range.snapshots.send_total_in_progress',
    'range.snapshots.sent_bytes.count',
    'range.snapshots.unknown.rcvd_bytes.count',
    'range.snapshots.unknown.sent_bytes.count',
    'range.splits.total.count',
    'rebalancing.cpunanospersecond',
    'rebalancing.lease.transfers.count',
    'rebalancing.queriespersecond',
    'rebalancing.range.rebalances.count',
    'rebalancing.readbytespersecond',
    'rebalancing.readspersecond',
    'rebalancing.requestspersecond',
    'rebalancing.state.imbalanced_overfull_options_exhausted.count',
    'rebalancing.writebytespersecond',
    'rebalancing.writespersecond',
    'replicas.leaders',
    'replicas.leaders.not_leaseholders',
    'replicas.leaders_invalid_lease',
    'replicas.leaseholders',
    'replicas.quiescent',
    'replicas.reserved',
    'replicas.uninitialized',
    'requests.slow.latch',
    'rocksdb.block.cache.hits',
    'rocksdb.block.cache.misses',
    'rocksdb.block.cache.usage',
    'rocksdb.bloom_filter.prefix.checked',
    'rocksdb.bloom_filter.prefix.useful',
    'rocksdb.compacted_bytes_read',
    'rocksdb.compacted_bytes_written',
    'rocksdb.compactions.total',
    'rocksdb.encryption.algorithm',
    'rocksdb.estimated_pending_compaction',
    'rocksdb.flushed_bytes',
    'rocksdb.flushes.total',
    'rocksdb.ingested_bytes',
    'rocksdb.memtable.total.size',
    'rocksdb.num_sstables',
    'rocksdb.read.amplification',
    'rocksdb.table.readers.mem.estimate',
    'rpc.batches.recv.count',
    'rpc.connection.avg_round_trip_latency',
    'rpc.connection.failures.count',
    'rpc.connection.healthy',
    'rpc.connection.healthy_nanos',
    'rpc.connection.heartbeats.count',
    'rpc.connection.inactive',
    'rpc.connection.unhealthy',
    'rpc.connection.unhealthy_nanos',
    'rpc.method.addsstable.recv.count',
    'rpc.method.adminchangereplicas.recv.count',
    'rpc.method.adminmerge.recv.count',
    'rpc.method.adminrelocaterange.recv.count',
    'rpc.method.adminscatter.recv.count',
    'rpc.method.adminsplit.recv.count',
    'rpc.method.admintransferlease.recv.count',
    'rpc.method.adminunsplit.recv.count',
    'rpc.method.adminverifyprotectedtimestamp.recv.count',
    'rpc.method.barrier.recv.count',
    'rpc.method.checkconsistency.recv.count',
    'rpc.method.clearrange.recv.count',
    'rpc.method.computechecksum.recv.count',
    'rpc.method.conditionalput.recv.count',
    'rpc.method.delete.recv.count',
    'rpc.method.deleterange.recv.count',
    'rpc.method.endtxn.recv.count',
    'rpc.method.export.recv.count',
    'rpc.method.gc.recv.count',
    'rpc.method.get.recv.count',
    'rpc.method.heartbeattxn.recv.count',
    'rpc.method.increment.recv.count',
    'rpc.method.initput.recv.count',
    'rpc.method.isspanempty.recv.count',
    'rpc.method.leaseinfo.recv.count',
    'rpc.method.merge.recv.count',
    'rpc.method.migrate.recv.count',
    'rpc.method.probe.recv.count',
    'rpc.method.pushtxn.recv.count',
    'rpc.method.put.recv.count',
    'rpc.method.queryintent.recv.count',
    'rpc.method.querylocks.recv.count',
    'rpc.method.queryresolvedtimestamp.recv.count',
    'rpc.method.querytxn.recv.count',
    'rpc.method.rangestats.recv.count',
    'rpc.method.recomputestats.recv.count',
    'rpc.method.recovertxn.recv.count',
    'rpc.method.refresh.recv.count',
    'rpc.method.refreshrange.recv.count',
    'rpc.method.requestlease.recv.count',
    'rpc.method.resolveintent.recv.count',
    'rpc.method.resolveintentrange.recv.count',
    'rpc.method.reversescan.recv.count',
    'rpc.method.revertrange.recv.count',
    'rpc.method.scan.recv.count',
    'rpc.method.subsume.recv.count',
    'rpc.method.transferlease.recv.count',
    'rpc.method.truncatelog.recv.count',
    'rpc.method.writebatch.recv.count',
    'rpc.streams.mux_rangefeed.active',
    'rpc.streams.mux_rangefeed.recv.count',
    'rpc.streams.rangefeed.active',
    'rpc.streams.rangefeed.recv.count',
}

SQL_METRICS = {
    'schedules.BACKUP.protected_age_sec',
    'schedules.BACKUP.protected_record_count',
    'schedules.CHANGEFEED.failed.count',
    'schedules.CHANGEFEED.started.count',
    'schedules.CHANGEFEED.succeeded.count',
    'schedules.backup.failed.count',
    'schedules.backup.last_completed_time',
    'schedules.backup.started.count',
    'schedules.backup.succeeded.count',
    'schedules.error',
    'schedules.malformed',
    'schedules.round.jobs_started',
    'schedules.round.reschedule_skip',
    'schedules.round.reschedule_wait',
    'schedules.scheduled.row.level.ttl.executor_failed.count',
    'schedules.scheduled_row_level_ttl_executor.started.count',
    'schedules.scheduled_row_level_ttl_executor.succeeded.count',
    'schedules.scheduled_schema_telemetry_executor.failed.count',
    'schedules.scheduled_schema_telemetry_executor.started.count',
    'schedules.scheduled_schema_telemetry_executor.succeeded.count',
    'schedules.scheduled_sql_stats_compaction_executor.failed.count',
    'schedules.scheduled_sql_stats_compaction_executor.started.count',
    'schedules.scheduled_sql_stats_compaction_executor.succeeded.count',
    'spanconfig.kvsubscriber.oldest_protected_record_nanos',
    'spanconfig.kvsubscriber.protected_record_count',
    'spanconfig.kvsubscriber.update_behind_nanos',
    'sql.bytesin.count',
    'sql.bytesout.count',
    'sql.conn.failures.count',
    'sql.conns',
    'sql.conns_waiting_to_hash',
    'sql.contention.resolver.failed_resolutions.count',
    'sql.contention.resolver.queue_size',
    'sql.contention.resolver.retries.count',
    'sql.contention.txn_id_cache.miss.count',
    'sql.contention.txn_id_cache.read.count',
    'sql.copy.count',
    'sql.copy.internal.count',
    'sql.copy.nonatomic.count',
    'sql.copy.nonatomic.internal.count',
    'sql.copy.nonatomic.started.count',
    'sql.copy.nonatomic.started.internal.count',
    'sql.copy.started.count',
    'sql.copy.started.internal.count',
    'sql.ddl.count',
    'sql.ddl.internal.count',
    'sql.ddl.started.count',
    'sql.ddl.started.internal.count',
    'sql.delete.count',
    'sql.delete.internal.count',
    'sql.delete.started.count',
    'sql.delete.started.internal.count',
    'sql.disk.distsql.current',
    'sql.disk.distsql.spilled.bytes.read.count',
    'sql.disk.distsql.spilled.bytes.written.count',
    'sql.distsql.contended.queries.count',
    'sql.distsql.dist_query_rerun_locally.count',
    'sql.distsql.dist_query_rerun_locally.failure_count.count',
    'sql.distsql.flows.active',
    'sql.distsql.flows.count',
    'sql.distsql.queries.active',
    'sql.distsql.queries.count',
    'sql.distsql.queries.spilled.count',
    'sql.distsql.select.count',
    'sql.distsql.select.internal.count',
    'sql.distsql.vec.openfds',
    'sql.failure.count',
    'sql.failure.internal.count',
    'sql.feature_flag_denial.count',
    'sql.full.scan.count',
    'sql.full.scan.internal.count',
    'sql.guardrails.full_scan_rejected.count',
    'sql.guardrails.full_scan_rejected.internal.count',
    'sql.guardrails.max_row_size_err.count',
    'sql.guardrails.max_row_size_err.internal.count',
    'sql.guardrails.max_row_size_log.count',
    'sql.guardrails.max_row_size_log.internal.count',
    'sql.guardrails.transaction_rows_read_err.count',
    'sql.guardrails.transaction_rows_read_err.internal.count',
    'sql.guardrails.transaction_rows_read_log.count',
    'sql.guardrails.transaction_rows_read_log.internal.count',
    'sql.guardrails.transaction_rows_written_err.count',
    'sql.guardrails.transaction_rows_written_err.internal.count',
    'sql.guardrails.transaction_rows_written_log.count',
    'sql.guardrails.transaction_rows_written_log.internal.count',
    'sql.hydrated_schema_cache.hits.count',
    'sql.hydrated_schema_cache.misses.count',
    'sql.hydrated_table_cache.hits.count',
    'sql.hydrated_table_cache.misses.count',
    'sql.hydrated_type_cache.hits.count',
    'sql.hydrated_type_cache.misses.count',
    'sql.hydrated_udf_cache.hits.count',
    'sql.hydrated_udf_cache.misses.count',
    'sql.insert.count',
    'sql.insert.internal.count',
    'sql.insert.started.count',
    'sql.insert.started.internal.count',
    'sql.insights.anomaly_detection.evictions.count',
    'sql.insights.anomaly_detection.fingerprints',
    'sql.insights.anomaly_detection.memory',
    'sql.leases.active',
    'sql.mem.bulk.current',
    'sql.mem.conns.current',
    'sql.mem.distsql.current',
    'sql.mem.internal.current',
    'sql.mem.internal.session.current',
    'sql.mem.internal.session.prepared.current',
    'sql.mem.internal.txn.current',
    'sql.mem.root.current',
    'sql.mem.sql.current',
    'sql.mem.sql.session.current',
    'sql.mem.sql.session.prepared.current',
    'sql.mem.sql.txn.current',
    'sql.misc.count',
    'sql.misc.internal.count',
    'sql.misc.started.count',
    'sql.misc.started.internal.count',
    'sql.new_conns.count',
    'sql.optimizer.fallback.count',
    'sql.optimizer.fallback.internal.count',
    'sql.optimizer.plan_cache.hits.count',
    'sql.optimizer.plan_cache.hits.internal.count',
    'sql.optimizer.plan_cache.misses.count',
    'sql.optimizer.plan_cache.misses.internal.count',
    'sql.pgwire_cancel.count',
    'sql.pgwire_cancel.ignored.count',
    'sql.pgwire_cancel.successful.count',
    'sql.pre_serve.bytesin.count',
    'sql.pre_serve.bytesout.count',
    'sql.pre_serve.conn.failures.count',
    'sql.pre_serve.mem.cur',
    'sql.pre_serve.new_conns.count',
    'sql.query.count',
    'sql.query.internal.count',
    'sql.query.started.count',
    'sql.query.started.internal.count',
    'sql.restart_savepoint.count',
    'sql.restart_savepoint.internal.count',
    'sql.restart_savepoint.release.count',
    'sql.restart_savepoint.release.internal.count',
    'sql.restart_savepoint.release.started.count',
    'sql.restart_savepoint.release.started.internal.count',
    'sql.restart_savepoint.rollback.count',
    'sql.restart_savepoint.rollback.internal.count',
    'sql.restart_savepoint.rollback.started.count',
    'sql.restart_savepoint.rollback.started.internal.count',
    'sql.restart_savepoint.started.count',
    'sql.restart_savepoint.started.internal.count',
    'sql.savepoint.count',
    'sql.savepoint.internal.count',
    'sql.savepoint.release.count',
    'sql.savepoint.release.internal.count',
    'sql.savepoint.release.started.count',
    'sql.savepoint.release.started.internal.count',
    'sql.savepoint.rollback.count',
    'sql.savepoint.rollback.internal.count',
    'sql.savepoint.rollback.started.count',
    'sql.savepoint.rollback.started.internal.count',
    'sql.savepoint.started.count',
    'sql.savepoint.started.internal.count',
    'sql.schema.invalid_objects',
    'sql.schema_changer.permanent_errors.count',
    'sql.schema_changer.retry_errors.count',
    'sql.schema_changer.running',
    'sql.schema_changer.successes.count',
    'sql.select.count',
    'sql.select.internal.count',
    'sql.select.started.count',
    'sql.select.started.internal.count',
    'sql.statements.active',
    'sql.statements.active.internal',
    'sql.stats.cleanup.rows_removed.count',
    'sql.stats.discarded.current.count',
    'sql.stats.flush.count',
    'sql.stats.flush.error.count',
    'sql.stats.mem.current',
    'sql.stats.reported.mem.current',
    'sql.temp_object_cleaner.active_cleaners',
    'sql.temp_object_cleaner.schemas_deletion_error.count',
    'sql.temp_object_cleaner.schemas_deletion_success.count',
    'sql.temp_object_cleaner.schemas_to_delete.count',
    'sql.txn.abort.count',
    'sql.txn.abort.internal.count',
    'sql.txn.begin.count',
    'sql.txn.begin.internal.count',
    'sql.txn.begin.started.count',
    'sql.txn.begin.started.internal.count',
    'sql.txn.commit.count',
    'sql.txn.commit.internal.count',
    'sql.txn.commit.started.count',
    'sql.txn.commit.started.internal.count',
    'sql.txn.contended.count',
    'sql.txn.contended.internal.count',
    'sql.txn.rollback.count',
    'sql.txn.rollback.internal.count',
    'sql.txn.rollback.started.count',
    'sql.txn.rollback.started.internal.count',
    'sql.txns.open',
    'sql.txns.open.internal',
    'sql.update.count',
    'sql.update.internal.count',
    'sql.update.started.count',
    'sql.update.started.internal.count',
    'sqlliveness.is_alive.cache_hits.count',
    'sqlliveness.is_alive.cache_misses.count',
    'sqlliveness.sessions_deleted.count',
    'sqlliveness.sessions_deletion_runs.count',
    'sqlliveness.write_failures.count',
    'sqlliveness.write_successes.count',
    'storage.batch_commit',
    'storage.batch_commit.commit_wait.duration',
    'storage.batch_commit.duration',
    'storage.batch_commit.l0_stall.duration',
    'storage.batch_commit.mem_stall.duration',
    'storage.batch_commit.sem_wait.duration',
    'storage.batch_commit.wal_queue_wait.duration',
    'storage.batch_commit.wal_rotation.duration',
    'storage.checkpoints',
    'storage.compactions.duration',
    'storage.compactions.keys.pinned',
    'storage.compactions.keys.pinned.bytes',
    'storage.disk_slow',
    'storage.disk_stalled',
    'storage.flush.ingest',
    'storage.flush.ingest.table',
    'storage.flush.ingest.table.bytes',
    'storage.flush.utilization',
    'storage.ingest',
    'storage.iterator.block_load.bytes',
    'storage.iterator.block_load.cached_bytes',
    'storage.iterator.block_load.read_duration',
    'storage.iterator.external.seeks',
    'storage.iterator.external.steps',
    'storage.iterator.internal.seeks',
    'storage.iterator.internal.steps',
    'storage.keys.range_key_set',
    'storage.keys.tombstone',
    'storage.marked_for_compaction_files',
    'storage.queue.store_failures.count',
    'storage.secondary_cache',
    'storage.secondary_cache.evictions',
    'storage.secondary_cache.reads_full_hit',
    'storage.secondary_cache.reads_multi_block',
    'storage.secondary_cache.reads_multi_shard',
    'storage.secondary_cache.reads_no_hit',
    'storage.secondary_cache.reads_partial_hit',
    'storage.secondary_cache.size',
    'storage.secondary_cache.write_back_failures',
    'storage.shared_storage.read',
    'storage.shared_storage.write',
    'storage.single_delete.ineffectual',
    'storage.single_delete.invariant_violation',
    'storage.wal.bytes_in',
    'storage.wal.bytes_written',
    'storage.write.stalls',
    'storage.write_stall_nanos',
    'sys.cgo.allocbytes',
    'sys.cgo.totalbytes',
    'sys.cgocalls',
    'sys.cpu.combined.percent.normalized',
    'sys.cpu.host.combined.percent_normalized',
    'sys.cpu.now.ns',
    'sys.cpu.sys.ns',
    'sys.cpu.sys.percent',
    'sys.cpu.user.ns',
    'sys.cpu.user.percent',
    'sys.fd.open',
    'sys.fd.softlimit',
    'sys.gc',
    'sys.gc.pause.ns',
    'sys.gc.pause.percent',
    'sys.go.allocbytes',
    'sys.go.totalbytes',
    'sys.goroutines',
    'sys.host.disk.io.time',
    'sys.host.disk.iopsinprogress',
    'sys.host.disk.read',
    'sys.host.disk.read.bytes',
    'sys.host.disk.read.time',
    'sys.host.disk.weightedio.time',
    'sys.host.disk.write',
    'sys.host.disk.write.bytes',
    'sys.host.disk.write.time',
    'sys.host.net.recv.bytes',
    'sys.host.net.recv.packets',
    'sys.host.net.send.bytes',
    'sys.host.net.send.packets',
    'sys.rss',
    'sys.runnable.goroutines.per_cpu',
    'sys.totalmem',
    'sys.uptime',
    'tenant.consumption.cross_region_network_ru.count',
    'tenant.consumption.external_io_egress_bytes',
    'tenant.consumption.external_io_ingress_bytes',
    'tenant.consumption.kv_request_units.count',
    'tenant.consumption.pgwire_egress_bytes',
    'tenant.consumption.read_batches',
    'tenant.consumption.read_bytes',
    'tenant.consumption.read_requests',
    'tenant.consumption.request_units.count',
    'tenant.consumption.sql_pods_cpu_seconds',
    'tenant.consumption.write_batches',
    'tenant.consumption.write_bytes',
    'tenant.consumption.write_requests',
    'txn.aborts.count',
    'txn.commit_waits.before_commit_trigger.count',
    'txn.commit_waits.count',
    'txn.commits.count',
    'txn.commits1PC.count',
    'txn.condensed_intent_spans.count',
    'txn.condensed_intent_spans_gauge',
    'txn.condensed_intent_spans_rejected.count',
    'txn.parallelcommits.auto_retries.count',
    'txn.parallelcommits.count',
    'txn.refresh.auto_retries.count',
    'txn.refresh.fail.count',
    'txn.refresh.fail_with_condensed_spans.count',
    'txn.refresh.memory_limit_exceeded.count',
    'txn.refresh.success.count',
    'txn.refresh.success_server_side.count',
    'txn.restarts.asyncwritefailure.count',
    'txn.restarts.commitdeadlineexceeded.count',
    'txn.restarts.readwithinuncertainty.count',
    'txn.restarts.serializable.count',
    'txn.restarts.txnaborted.count',
    'txn.restarts.txnpush.count',
    'txn.restarts.unknown.count',
    'txn.restarts.writetooold.count',
    'txn.restarts.writetoooldmulti.count',
    'txn.rollbacks.async.failed.count',
    'txn.rollbacks.failed.count',
    'txn.server_side.1PC.failure.count',
    'txn.server_side.1PC.success.count',
    'txn.server_side_retry.read_evaluation.failure.count',
    'txn.server_side_retry.read_evaluation.success.count',
    'txn.server_side_retry.uncertainty_interval_error.failure.count',
    'txn.server_side_retry.uncertainty_interval_error.success.count',
    'txn.server_side_retry.write_evaluation.failure.count',
    'txn.server_side_retry.write_evaluation.success.count',
}


def assert_metrics(aggregator):
    metadata_metrics = get_metadata_metrics()

    expected_metrics = copy.deepcopy(EXPECTED_METRICS)

    if version.parse(COCKROACHDB_VERSION) >= version.parse('23.0.0'):
        expected_metrics.extend(COCKROACHDB_23_METRICS)

    for metric in expected_metrics:
        aggregator.assert_metric('cockroachdb.{}'.format(metric), at_least=0)

    # Custom transformer
    aggregator.assert_metric('cockroachdb.build.timestamp')
    aggregator.assert_metrics_using_metadata(metadata_metrics, check_submission_type=True)
    assert_service_checks(aggregator)


def get_fixture_path(filename):
    return os.path.join(HERE, 'fixtures', filename)
